1. /* scomdiv.cpp by K.Tsuru */
  2. // function ID = 904
  3. /**************************
  4. SComplex class
  5. division (*this)/z = (a+bi)/(c+di)
  6. (a+bi)(c-di) ac+bd +(bc-ad)i a*(c/d)+b + {b*(c/d)-a}i a*r+b + (b*r-a)i
  7. =------------ = ------------- = ------------------------- = ----------------- (r = c/d)
  8. c^2+d^2 z.Norm() c*(c/d) + d c*r + d
  9. On May 16, 2010
  10. Tested again
  11. On June 20, 2015
  12. Changed onece more by the
  13. [reference] Kouya, Tomonori "Shohokarano FFT" chap. 3.
  14. url : http://na-inet.jp/fft/ (in Japanese)
  15. **************************/
  16. #ifndef SN_H
  17. #include "sn.h"
  18. #endif
  19. static const char* func = "SComplex /";
  20. SComplex& SComplex::operator/=(const SComplex& z)
  21. {
  22. if ( z.IsZero(904) ) im.SetError(im.DIVIDED_BY_ZERO, func, 904);
  23. // (a+bi)/c
  24. if (z.im.Sign(904) == SNumber::ZERO) return ((*this) /= z.re); // "z" is real number.
  25. // (a+bi)/ci = b/c -(a/c)i
  26. if (z.re.Sign(904) == SNumber::ZERO) {
  27. const SDouble r = im / z.im;
  28. im = -re / z.im;
  29. re = r;
  30. return *this;
  31. }
  32. #if 0
  33. const SDouble r = re * z.re + im * z.im;
  34. const SDouble recNorm_z = DReciprocal( z.Norm() ); // = 1/(c^2 + d^2)
  35. im = ( im * z.re - re * z.im ) * recNorm_z;
  36. re = r * recNorm_z;
  37. #else
  38. SDouble r, s, w;
  39. if(z.re >= z.im) {
  40. r = z.im / z.re; s = z.re + z.im * r;
  41. w = (re + im * r) / s;
  42. im = (-re * r + im) / s;
  43. re = w;
  44. }else {
  45. r = z.re / z.im; s = z.re * r + z.im;
  46. w = (re * r + im) / s;
  47. im = (-re + im * r)/ s;
  48. re = w;
  49. }
  50. #endif
  51. return *this;
  52. }

scomdiv.cpp : last modifiled at 2015/08/09 18:06:41(1,541 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:09 (Fri Oct 06 15:27:09 2017).